package com.ecoolex.discount.sales.api.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ecoolex.discount.sales.pojo.YwGiftOrderDeviceRecordDTO;
import com.ecoolex.discount.sales.ws.YouWorldOrderRecordService;
import com.ecoolex.framework.common.util.io.HttpUtil;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/youworld/order")
@CrossOrigin(origins = "*")
@Slf4j
public class YwGiftOrderDeviceRecordController {

	@Reference
    YouWorldOrderRecordService youWorldOrderRecordService;
	
	@PostMapping("/deviceinfo/record")
	public Resp record(@RequestBody YwGiftOrderDeviceRecordDTO record, HttpServletRequest request) {
		try {
            youWorldOrderRecordService.userDeviceInfoRecord(record, HttpUtil.getIpAddr(request), YwGiftOrderDeviceRecordController.class.getSimpleName());
        }catch (Exception e){
            log.info("yw-gift-order-device-record",e);
            return Resp.error(e.getMessage());
        }
		return Resp.ok("ok");
	}
	
	@Data
    public static class Resp {
        private boolean success;
        private String message;
        public static Resp error(String message){
            Resp resp = new Resp();
            resp.setSuccess(false);
            resp.setMessage(message);
            return  resp;
        }
        public static Resp ok(String message){
            Resp resp = new Resp();
            resp.setSuccess(true);
            resp.setMessage(message);
            return  resp;
        }

    }
}
